package com.hulytu.invasion.plugin;

public class MethodParam {

    public Object thisObject;

    public String method;

    public Object[] args;

    private Object result;

    private Throwable throwable;

    private transient int modCount;

    public MethodParam() {
    }

    public MethodParam(String method, Object... args) {
        this(null, method, args);
    }

    public MethodParam(Object thisObject, String method, Object... args) {
        this.thisObject = thisObject;
        this.args = args;
        this.method = method;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
        this.throwable = null;
        this.modCount++;
    }

    /**
     * Returns the {@link Throwable} thrown by the method, or {@code null}.
     */
    public Throwable getThrowable() {
        return throwable;
    }

    /**
     * Returns true if an exception was thrown by the method.
     */
    public boolean hasThrowable() {
        return throwable != null;
    }

    public void setThrowable(Throwable throwable) {
        this.throwable = throwable;
        this.result = null;
        this.modCount++;
    }

    /**
     * @return 返回true 表示方法被执行了，否则认为方法没有执行
     */
    public boolean isExecuted() {
        return modCount > 0;
    }

    public int getModCount() {
        return modCount;
    }

    /**
     * Returns the result of the method call, or throws the Throwable caused by it.
     */
    public Object getResultOrThrowable() throws Throwable {
        if (throwable != null)
            throw throwable;
        return result;
    }
}
